14. ROS Nodes

14 Ros Nodes

Scope Resolution Operator

In C++, the scope resolution operator "::" is commonly used to recognize hidden namespaces. In this program, the scope resolution operator is qualifying the "ros" namespace so we can still use it to define a function outside a class or access a class static variables.

Catkin Workspace

Before you clone the simple_arm_c ROS package and launch the nodes, make sure you already have a catkin workspace to work in. If not, create and initialize a catkin workspace by following along the instruction from term 1 of the Robotics nanodegree program!

Comparison

It's recommended to go over the simple_arm package from term 1 and compare the simple_mover python script to the C++ one. While comparing both ROS publisher scripts, you will be able to identify the difference in syntax between both programming languages.

Launch ROS Nodes

1- Open a Linux terminal and navigate to the src folder in your catkin workspace:

$ cd ~/catkin_ws/src

2- While in catkin workspace, clone the package from GitHub:

$ git clone https://github.com/udacity/simple_arm_c.git

3- Now, source your environment:

$ cd ~/catkin_ws
$ source devel/setup.bash

4- After sourcing your environment, build the packages:

$ catkin_make

5- Make sure to install the missing system dependencies as in Term 1:

$ rosdep install -i simple_arm_c

6-Now, launch the nodes :

$ roslaunch simple_arm_c robot_spawn.launch 

You should be able to see each revolute joint rotating between -pi/2 to pi/2 over time.

Additional Resources

  • NodeHandles:
    Review this official ROS document which explains the purpose of NodeHandles inside a C++ program.
  • Publisher & Subscriber:
    This is the official ROS tutorial which covers how to write a publisher and subscriber node in C++.
  • Service & Client:
    This is the official ROS tutorial which covers how to write a service and client node in C++.